import Vue from 'vue'
import VueJsonp from 'vue-jsonp'

Vue.use(VueJsonp)

export let shareInfo = {
    title: '测试分享标题',
    desc: '测试分享摘要',
    timeline: '测试分享朋友圈',
    imgUrl: process.env.VUE_APP_BASE_URL + 'img/shareImg.jpg',
    link: process.env.VUE_APP_LINK_URL + 'project/',
}

export const wxConfig = ()=>{
    let url = 'https://w1.thefront.com.cn/weixports/getwxapi.php';
    let param = {
        "request": {
            "body": { "url": window.location.href.split('#')[0] },
            "head": {
                "public_key": "1",
                "secret_key": "1",
                "timestamp": "1"
            }
        }
    }
    Vue.jsonp(url, param).then(res=>{
        wx.config({
            debug: false,
            appId: res.signPackage.appId,
            timestamp: res.signPackage.timestamp,
            nonceStr: res.signPackage.nonceStr,
            signature: res.signPackage.signature,
            jsApiList: [
                'onMenuShareTimeline',
                'onMenuShareAppMessage',
                'updateAppMessageShareData',
                'updateTimelineShareData',
            ]
        });
        wx.ready(function(){
            wx.updateAppMessageShareData({
                title: shareInfo.title,
                desc: shareInfo.desc,
                imgUrl: shareInfo.imgUrl,
                link: shareInfo.link,
                success: function(){
                    ga('send','event','nav','share','message');
                }
            });
            wx.updateTimelineShareData({
                title: shareInfo.timeline,
                imgUrl: shareInfo.imgUrl,
                link: shareInfo.link,
                success: function(){
                    ga('send','event','nav','share','timeline');
                }
            });
        });
    }).catch(err=>{
        console.error(err);
    })
}
